package com.fit4as.util.reflect
{

public class Field
{
	//
    private var name : String;
    private var declaringClass : Class;
    private var type : Class;
    private var componentType : Class;

    public function Field( declaringClass : Class, name : String, type : Class = null, componentType : Class = null )
    {
        this.declaringClass = declaringClass;
        this.name = name;
        this.type = type;
        this.componentType = componentType;
    }

    public function get( target : Object ) : *
    {
        return target[ name ];
    }

    public function set( target : Object, value : * ) : *
    {
        //t race("set " + [ target, name, value ]);
        target[ name ] = value;
        return value;
    }

    public function getType() : Class
    {
    	if( type == null ) type = ClassUtil.getFieldType( declaringClass, name );
        return type;
    }

    public function setByte( target : Object, value : int) : void
    {
        set(target, value);
    }

    public function setShort( target : Object, value : int) : void
    {
        set(target, value);
    }

    public function setInt( target : Object, value : int) : void
    {
        set(target, value);
    }

    public function setLong( target : Object, value : int) : void
    {
        set(target, value);
    }

    public function setFloat( target : Object, value : Number) : void
    {
        set(target, value);
    }

    public function setDouble( target : Object, value : Number) : void
    {
        set(target, value);
    }

    public function setChar( target : Object, value : String) : void
    {
        set(target, value);
    }

    public function setBoolean( target : Object, value : Boolean) : void
    {
        set(target, value);
    }
    
    public function toString() : String
    {
        return "[object Field"
                + " name:" + name
                + " declaringClass:" + declaringClass
            //+ " type:" + getType()
                + "]";

    }

	public function setComponentType( type : Class ) : void
	{
		this.componentType = type;
	}
	
	public function getComponentType() : Class
	{
		return componentType;
	}
}
}